<?php

include_once("core/controller.php");
include_once("core/libs/file.php");
include_once("core/versionHandler.php");
/**
 * This Controller is used to install a version
 * @copyright inovia
 * @package oolime_manager 
 *
 */
class UpdateVersion extends Controller {
   
   
   //todo verifier le niveau d'utilisateur
   protected function isLegitimate(){
      if(!$this->request->exist(Array("number")) ) {
      $this->response->addError("Le numero de version n'est pas renseigné.");
      return false;
    }
      return true;
   }



   /**
    * Function doing the actions of the Controller
    * 
    */
   protected function actions(){
   //recuperer des infos
   $versionH=new VersionHandler("");
   
   
   $number=$this->request->get("number");
   
   //$version=$versionH->getVersionByNumber($versionH->getMoreRecent());
   $version=$versionH->getVersionByNumber($number);
   //info
   
   //echo("Vous allez mettre à jour votre framework pour obtenir la version ".$version->getNumber()." avec le surnom ".$version->getSurname()." <br /> ");
   //echo ("Commentaires :".$version->getComments()." <br />");
   
   $nameSource=$version->path;
   
   $tab=$version->getcontainsD();
   if(count($tab)){
     foreach($tab as $pathDir){
       //echo $nameSource."/".$pathDir;
       dircopy($nameSource."/".$pathDir,$pathDir);
     }
   }
   
   $tab=$version->getcontainsF();
   if(count($tab)){
     foreach($tab as $pathF){
       fcopy($nameSource."/".$pathF,$pathF);
     }
   }
      //recuperer des tables...
    //$this->globals->dataBase->exportTables(Array("eventdispatcher","user"),"export/export.sql.gz");
    
    //recuperer des fichiers
    //copy("http://www.google.fr","here");
    
    $this->response->setXSLT("views/manager/install.xsl");

   }


   /**
    * Function doing default actions of the Controller
    *
    */
   protected function defaultActions(){
      
   }

}



?>
